using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RestUpMVC.Representation;
using RestUpMVC.Test.TestClasses;

namespace RestUpMVC.Test.Representation
{
    [TestClass]
    public class RepresentationFactoryTest
    {
        [TestMethod]
        [ExpectedException(typeof(InvalidOperationException))]
        public void Add_ShouldThrowAnExceptionIfARepresentationWithTheGivenContentTypeHasAlreadyBeenAdded()
        {
            var factory = new RepresentationFactory();
            factory.Add(new TestRepresentation());
            factory.Add(new TestRepresentation());
        }

        [TestMethod]
        public void Replace_ShouldReplaceTheExistingRepresentationWithTheNewOne()
        {
            
        }

        [TestMethod]
        public void RepresentationForContentTypeExists_ShouldReturnTrueIfARepresentationWithTheGivenContentTypeHasAlreadyBeenAdded()
        {
            var factory = new RepresentationFactory();
            var testRepresentation = new TestRepresentation();
            factory.Add(testRepresentation);
            Assert.IsTrue(factory.RepresentationForContentTypeExists(testRepresentation.ContentType));
        }

        [TestMethod]
        public void RepresentationForContentTypeExists_ShouldReturnFalseIfARepresentationWithTheGivenContentTypeHasNotBeenAdded()
        {
            var factory = new RepresentationFactory();
            var testRepresentation = new TestRepresentation();
            factory.Add(testRepresentation);
            Assert.IsTrue(factory.RepresentationForContentTypeExists(testRepresentation.ContentType));
        }

        [TestMethod]
        public void GetRepresentationForContentType_ShouldReturnTheRepresentationForTheGivenContentType()
        {
            var factory = new RepresentationFactory();
            var testRepresentation = new TestRepresentation();
            factory.Add(testRepresentation);
            var foundRepresentation = factory.GetRepresentationForContentType(testRepresentation.ContentType, null);
            Assert.AreEqual(testRepresentation.ContentType, foundRepresentation.ContentType);
        }

        [TestMethod]
        public void GetRepresentationForContentType_ShouldNotBeCaseSensitive()
        {
            var factory = new RepresentationFactory();
            var testRepresentation = new TestRepresentation();
            factory.Add(testRepresentation);
            var foundRepresentation = factory.GetRepresentationForContentType(testRepresentation.ContentType.ToUpper(), null);
            Assert.AreEqual(testRepresentation.ContentType, foundRepresentation.ContentType);
        }
    }
}